<?php
/*
 * Created on 22 mars 07
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
 class TasksController extends AppController{
 	var $name = 'Tasks';
 	var $helpers = array('Html', 'Javascript', 'Ajax');
 	
 	function index()
 	{
 		$this->set('data', $this->Task->findAll());
 	}
 	
 	function add()
 	{
 		if(!empty($this->params['data']))
 		{
 			if($this->Task->save($this->data))
 			{
 				$this->set('data', $this->Task->findAll());
 				$this->render('todo', 'ajax');
 			}else{
 				//do nothing
 			}
 		}
 	}
 	
 	function done($id = null)
 	{
 		//move task from todo to done
 		$this->Task->id = $id;
 		$this->params['data']['Task']['done'] = 1;
 		if($this->Task->save($this->params['data']))
 		{
 			$this->set('data', $this->Task->findAll());
 			$this->render('done', 'ajax');
 		}
 	}
 	
 	function undo($id)
 	{
 		//move task from done to todo
 		$this->Task->id = $id;
 		$this->params['data']['Task']['done'] = 0;
 		if($this->Task->save($this->params['data']))
 		{
 			$this->set('data', $this->Task->findAll());
 			$this->render('todo', 'ajax');
 		}
 	}
 	
 	function delete($id)
 	{
 		$this->Task->del($id);
 		$this->set('data', $this->Task->findAll());
 		$this->render('done', 'ajax');
 	}
 	
 	
 }
?>
